﻿/**  PACS v1.0
* JC_MachineAnalysis.cs
*
* 类 名： JC_MachineAnalysis
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:29   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_MachineAnalysis
	/// </summary>
	public partial class JC_MachineAnalysis
	{
		public JC_MachineAnalysis()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from JC_MachineAnalysis");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_MachineAnalysis model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.SheBeiChangJia != null)
			{
				strSql1.Append("SheBeiChangJia,");
				strSql2.Append("'"+model.SheBeiChangJia+"',");
			}
			if (model.SheBeiChangJiaNO != null)
			{
				strSql1.Append("SheBeiChangJiaNO,");
				strSql2.Append("'"+model.SheBeiChangJiaNO+"',");
			}
			if (model.ShengChanPiCi != null)
			{
				strSql1.Append("ShengChanPiCi,");
				strSql2.Append("'"+model.ShengChanPiCi+"',");
			}
			if (model.SheBeiLeiXing != null)
			{
				strSql1.Append("SheBeiLeiXing,");
				strSql2.Append("'"+model.SheBeiLeiXing+"',");
			}
			if (model.SheBeiXingHao != null)
			{
				strSql1.Append("SheBeiXingHao,");
				strSql2.Append("'"+model.SheBeiXingHao+"',");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql1.Append("ChuangJianShiJian,");
				strSql2.Append("'"+model.ChuangJianShiJian+"',");
			}
			if (model.ChuangJianRen != null)
			{
				strSql1.Append("ChuangJianRen,");
				strSql2.Append("'"+model.ChuangJianRen+"',");
			}
			if (model.ChuangJianRenNO != null)
			{
				strSql1.Append("ChuangJianRenNO,");
				strSql2.Append("'"+model.ChuangJianRenNO+"',");
			}
			if (model.ChuangJianRenID != null)
			{
				strSql1.Append("ChuangJianRenID,");
				strSql2.Append("'"+model.ChuangJianRenID+"',");
			}
			if (model.KeYongBiaoShi != null)
			{
				strSql1.Append("KeYongBiaoShi,");
				strSql2.Append("'"+model.KeYongBiaoShi+"',");
			}
			if (model.JieXiClassNameSpace != null)
			{
				strSql1.Append("JieXiClassNameSpace,");
				strSql2.Append("'"+model.JieXiClassNameSpace+"',");
			}
			strSql.Append("insert into JC_MachineAnalysis(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_MachineAnalysis model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_MachineAnalysis set ");
			if (model.SheBeiChangJia != null)
			{
				strSql.Append("SheBeiChangJia='"+model.SheBeiChangJia+"',");
			}
			else
			{
				strSql.Append("SheBeiChangJia= null ,");
			}
			if (model.SheBeiChangJiaNO != null)
			{
				strSql.Append("SheBeiChangJiaNO='"+model.SheBeiChangJiaNO+"',");
			}
			else
			{
				strSql.Append("SheBeiChangJiaNO= null ,");
			}
			if (model.ShengChanPiCi != null)
			{
				strSql.Append("ShengChanPiCi='"+model.ShengChanPiCi+"',");
			}
			else
			{
				strSql.Append("ShengChanPiCi= null ,");
			}
			if (model.SheBeiLeiXing != null)
			{
				strSql.Append("SheBeiLeiXing='"+model.SheBeiLeiXing+"',");
			}
			else
			{
				strSql.Append("SheBeiLeiXing= null ,");
			}
			if (model.SheBeiXingHao != null)
			{
				strSql.Append("SheBeiXingHao='"+model.SheBeiXingHao+"',");
			}
			else
			{
				strSql.Append("SheBeiXingHao= null ,");
			}
			if (model.ChuangJianShiJian != null)
			{
				strSql.Append("ChuangJianShiJian='"+model.ChuangJianShiJian+"',");
			}
			else
			{
				strSql.Append("ChuangJianShiJian= null ,");
			}
			if (model.ChuangJianRen != null)
			{
				strSql.Append("ChuangJianRen='"+model.ChuangJianRen+"',");
			}
			else
			{
				strSql.Append("ChuangJianRen= null ,");
			}
			if (model.ChuangJianRenNO != null)
			{
				strSql.Append("ChuangJianRenNO='"+model.ChuangJianRenNO+"',");
			}
			else
			{
				strSql.Append("ChuangJianRenNO= null ,");
			}
			if (model.ChuangJianRenID != null)
			{
				strSql.Append("ChuangJianRenID='"+model.ChuangJianRenID+"',");
			}
			else
			{
				strSql.Append("ChuangJianRenID= null ,");
			}
			if (model.KeYongBiaoShi != null)
			{
				strSql.Append("KeYongBiaoShi='"+model.KeYongBiaoShi+"',");
			}
			else
			{
				strSql.Append("KeYongBiaoShi= null ,");
			}
			if (model.JieXiClassNameSpace != null)
			{
				strSql.Append("JieXiClassNameSpace='"+model.JieXiClassNameSpace+"',");
			}
			else
			{
				strSql.Append("JieXiClassNameSpace= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_MachineAnalysis ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_MachineAnalysis ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_MachineAnalysis GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,SheBeiChangJia,SheBeiChangJiaNO,ShengChanPiCi,SheBeiLeiXing,SheBeiXingHao,ChuangJianShiJian,ChuangJianRen,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,JieXiClassNameSpace ");
			strSql.Append(" from JC_MachineAnalysis ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.JC_MachineAnalysis model=new Pacs.Model.JC_MachineAnalysis();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_MachineAnalysis DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_MachineAnalysis model=new Pacs.Model.JC_MachineAnalysis();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["SheBeiChangJia"]!=null)
				{
					model.SheBeiChangJia=row["SheBeiChangJia"].ToString();
				}
				if(row["SheBeiChangJiaNO"]!=null)
				{
					model.SheBeiChangJiaNO=row["SheBeiChangJiaNO"].ToString();
				}
				if(row["ShengChanPiCi"]!=null)
				{
					model.ShengChanPiCi=row["ShengChanPiCi"].ToString();
				}
				if(row["SheBeiLeiXing"]!=null)
				{
					model.SheBeiLeiXing=row["SheBeiLeiXing"].ToString();
				}
				if(row["SheBeiXingHao"]!=null)
				{
					model.SheBeiXingHao=row["SheBeiXingHao"].ToString();
				}
				if(row["ChuangJianShiJian"]!=null && row["ChuangJianShiJian"].ToString()!="")
				{
					model.ChuangJianShiJian=DateTime.Parse(row["ChuangJianShiJian"].ToString());
				}
				if(row["ChuangJianRen"]!=null)
				{
					model.ChuangJianRen=row["ChuangJianRen"].ToString();
				}
				if(row["ChuangJianRenNO"]!=null)
				{
					model.ChuangJianRenNO=row["ChuangJianRenNO"].ToString();
				}
				if(row["ChuangJianRenID"]!=null)
				{
					model.ChuangJianRenID=row["ChuangJianRenID"].ToString();
				}
				if(row["KeYongBiaoShi"]!=null)
				{
					model.KeYongBiaoShi=row["KeYongBiaoShi"].ToString();
				}
				if(row["JieXiClassNameSpace"]!=null)
				{
					model.JieXiClassNameSpace=row["JieXiClassNameSpace"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,SheBeiChangJia,SheBeiChangJiaNO,ShengChanPiCi,SheBeiLeiXing,SheBeiXingHao,ChuangJianShiJian,ChuangJianRen,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,JieXiClassNameSpace ");
			strSql.Append(" FROM JC_MachineAnalysis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,SheBeiChangJia,SheBeiChangJiaNO,ShengChanPiCi,SheBeiLeiXing,SheBeiXingHao,ChuangJianShiJian,ChuangJianRen,ChuangJianRenNO,ChuangJianRenID,KeYongBiaoShi,JieXiClassNameSpace ");
			strSql.Append(" FROM JC_MachineAnalysis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_MachineAnalysis ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_MachineAnalysis T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

